package com.dt.app.api.test.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.dt.app.modules.test.entities.SchoolCourseSelection;
import com.dt.app.modules.test.vo.SchoolCourseSelectionBean;
import com.dt.app.api.test.mapper.SchoolCourseSelectionMapper;
import com.dt.app.api.test.service.ISchoolCourseSelectionService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dt.app.modules.test.vo.SchoolCourseSelectionCount;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 鸿源塔基
 * @since 2024-02-22
 */
@Service
public class SchoolCourseSelectionServiceImpl extends ServiceImpl<SchoolCourseSelectionMapper, SchoolCourseSelection> implements ISchoolCourseSelectionService {
    public SchoolCourseSelection getEntity(SchoolCourseSelectionBean bean){
        SchoolCourseSelection entity = new SchoolCourseSelection();
        entity.setSchoolCourseSelectionId(bean.getSchoolCourseSelectionId());
        entity.setName(bean.getName());
        entity.setClassName(bean.getClassName());
        entity.setNumb(bean.getNumb());
        entity.setPhone(bean.getPhone());
        entity.setCourse(bean.getCourse());
        return entity;
    }
    public SchoolCourseSelectionBean getBean(SchoolCourseSelection entity){
        SchoolCourseSelectionBean bean = new SchoolCourseSelectionBean();
        bean.setSchoolCourseSelectionId(entity.getSchoolCourseSelectionId());
        bean.setName(entity.getName());
        bean.setClassName(entity.getClassName());
        bean.setNumb(entity.getNumb());
        bean.setPhone(entity.getPhone());
        bean.setCourse(entity.getCourse());
        return bean;
    }
    public List<SchoolCourseSelection> getEntitys(String className, String name){
        QueryWrapper<SchoolCourseSelection> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("class_name",className).eq("name",name);
        return this.list(queryWrapper);
    }
    public List<SchoolCourseSelectionBean> getBeans(String grade, String course){
        List<SchoolCourseSelectionBean> rss = new ArrayList<>();
        List<SchoolCourseSelection> lsdf = getList(grade, course);
        if(lsdf==null || lsdf.size()<1)return rss;
        for(SchoolCourseSelection s:lsdf){
            SchoolCourseSelectionBean b=new SchoolCourseSelectionBean();
            BeanUtils.copyProperties(s,b);
            rss.add(b);
        }
        return rss;
    }
    public List<SchoolCourseSelection> getList(String grade, String course){
        QueryWrapper<SchoolCourseSelection> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("grade",grade).eq("course",course);
        return this.list(queryWrapper);
    }
    public int getCount(String grade,String course){
        QueryWrapper<SchoolCourseSelection> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("grade",grade).eq("course",course);
        return (int)this.count(queryWrapper);
    }
    public List<SchoolCourseSelectionCount> getCounts(){
        return this.baseMapper.getCounts();
    }
    public int getCountTotal(){
        QueryWrapper<SchoolCourseSelection> queryWrapper=new QueryWrapper<>();
        return (int)(this.count(queryWrapper)/2);//每个人选两个课
    }
}
